//
//  CoordinateConvertTool.m
//  Runone
//
//  Created by runone02 on 16/11/9.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "CoordinateConvertTool.h"
#import <MAMapKit/MAMapKit.h>
#import <AMapFoundationKit/AMapFoundationKit.h>
#import "AllLastestVehicleDynamic.h"
#import "PileInfo.h"
#import "DeviceBaseInfo.h"
#import "StationModel.h"
#import "CurrentEvent.h"
#import "HighwayMergeInfoModel.h"

static CoordinateConvertTool *_singleton = nil;
@implementation CoordinateConvertTool


+ (instancetype)sharedCoordinateTool {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _singleton = [[CoordinateConvertTool alloc] init];
    });
    return _singleton;
}

/*
 * 所有收费站
 */

- (NSArray *) convertAllStationCoorToMapCoor:(NSArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (StationModel *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.Latitude, model.Longitude), AMapCoordinateTypeGPS);
        model.Latitude   = Ret.latitude;
        model.Longitude  = Ret.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}

// 桩号
- (NSArray *) convertPileNOCoorToMapCoor:(NSArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (PileInfo *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.Latitude, model.Longitude), AMapCoordinateTypeGPS);
        model.Latitude   = Ret.latitude;
        model.Longitude  = Ret.longitude;
        CLLocationCoordinate2D leftRet = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.LeftLatitude, model.LeftLongitude), AMapCoordinateTypeGPS);
        model.LeftLatitude  = leftRet.latitude;
        model.LeftLongitude = leftRet.longitude;
        CLLocationCoordinate2D rightRet = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.RightLatitude, model.RightLongitude), AMapCoordinateTypeGPS);
        model.RightLatitude  = rightRet.latitude;
        model.RightLongitude = rightRet.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}

//高速干道
- (NSArray *) convertHighWayDeviceCoorToMapCoor:(NSMutableArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (DeviceBaseInfo *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.Latitude, model.Longitude), AMapCoordinateTypeGPS);
        model.Latitude   = Ret.latitude;
        model.Longitude  = Ret.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}



//两客一危
- (NSMutableArray *) convertVehicleCoorToMapCoor:(NSArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (AllLastestVehicleDynamic *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.Latitude, model.Longitude), AMapCoordinateTypeGPS);
        model.Latitude   = Ret.latitude;
        model.Longitude  = Ret.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}

/*
 * 收费站
 */
- (NSArray *) convertStationCoorToMapCoor:(NSArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (HighwayMergeInfoModel *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.mergeJson.Latitude , model.mergeJson.Longitude), AMapCoordinateTypeGPS);
        model.mergeJson.Latitude    = Ret.latitude ;
        model.mergeJson.Longitude   = Ret.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}

/*
 * 设备
 */
- (NSArray *) convertAllDevicesCoorToMapCoor:(NSArray *)array {
    NSMutableArray *rebackArray = [[NSMutableArray alloc] init];
    for (DeviceBaseInfo *model in array) {
        CLLocationCoordinate2D Ret = AMapCoordinateConvert(CLLocationCoordinate2DMake(model.Latitude , model.Longitude), AMapCoordinateTypeGPS);
        model.Latitude    = Ret.latitude ;
        model.Longitude   = Ret.longitude;
        [rebackArray addObject:model];
    }
    return rebackArray;
}



@end
